<?php

namespace App\Http\Requests;

class TopicRequest extends Request
{
    public function rules()
    {
        switch ($this->method()) {
            // CREATE
            case 'POST':
                // UPDATE
            case 'PUT':
            case 'PATCH':
            {
                return [
                    'title' => 'required|min:2',
                    'body' => 'required|min:3',
                    'category_id' => 'required|numeric',
                    'tags' => 'nullable|array|max:5',
                    'publish' => 'required|boolean',
                ];
            }
            case 'GET':
            case 'DELETE':
            default:
            {
                return [];
            }
        }
    }

    public function messages()
    {
        return [
            'title.min' => '标题必须至少两个字符',
            'body.min' => '文章内容必须至少三个字符',
            'tags.max' => '标签最多选五个',
        ];
    }

    public function attributes()
    {
        return [
            'body' => '内容',
            'tags' => '标签',
            'publish' => '发布',
        ];
    }
}
